package com.muye.dianli.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.muye.constant.ConstantPersonalInfo;
import com.muye.dianli.R;

/**
 * 我的页面
 * 
 * @author TangChao
 * 
 */
public class MineActivity extends Activity implements OnClickListener
{
	/**
	 * 昵称
	 */
	private TextView nickName;
	
	/**
	 * 电话
	 */
	private TextView phone;
	
	/**
	 * 积分
	 */
	private TextView integral;
	
	/**
	 * 最后登录时间
	 */
	private TextView lastTime;
	
	/**
	 * 性别
	 */
	private TextView sex;
	
	/**
	 * 地址
	 */
	private TextView address;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.mine_layout);
		createTitle();
		initWidget();
	}
	
	@Override
	protected void onResume()
	{
		super.onResume();
		loadData();
	}
	
	@Override
	protected void onDestroy()
	{
		super.onDestroy();
	}
	
	/**
	 * 初始化标题栏
	 */
	private void createTitle()
	{
		TextView titleName = (TextView) findViewById(R.id.title_bar_name_text_view);
		titleName.setText("我的");
		titleName.setTextColor(getResources().getColor(R.color.white));
		ImageView leftBtn = (ImageView) findViewById(R.id.title_bar_left_image_view);
		leftBtn.setImageResource(R.drawable.title_back_icon);
		leftBtn.setVisibility(View.VISIBLE);
		leftBtn.setOnClickListener(this);
	}
	
	/**
	 * 初始化控件
	 */
	private void initWidget()
	{
		// 信息初始化
		nickName = (TextView) findViewById(R.id.mine_layout_nick_name_text);
		phone = (TextView) findViewById(R.id.mine_layout_phone_text);
		integral = (TextView) findViewById(R.id.mine_layout_integral_text);
		lastTime = (TextView) findViewById(R.id.mine_layout_last_time_text);
		sex = (TextView) findViewById(R.id.mine_layout_sex_text);
		address = (TextView) findViewById(R.id.mine_layout_address_text);
		// 修改账户
		TextView modifyAccountBtn = (TextView) findViewById(R.id.mine_layout_modify_accout);
		modifyAccountBtn.setOnClickListener(this);
		// 购物车
		TextView shoppingCartBtn = (TextView) findViewById(R.id.mine_layout_shopping_cart);
		shoppingCartBtn.setOnClickListener(this);
		// 我的评论
		TextView commentBtn = (TextView) findViewById(R.id.mine_layout_comment);
		commentBtn.setOnClickListener(this);
	}
	
	/**
	 * 加载数据
	 */
	private void loadData()
	{
		ImageView userImage = (ImageView) findViewById(R.id.mine_layout_user_image);
		nickName.setText("昵称: " + ConstantPersonalInfo.name);
		phone.setText("电话: " + ConstantPersonalInfo.mobilePhone);
		integral.setText("积分: " + ConstantPersonalInfo.integral);
		lastTime.setText("最后登陆时间: " + ConstantPersonalInfo.lastTime);
		if (ConstantPersonalInfo.sex.equals("1"))
		{
			sex.setText("性别: 男");
			userImage.setImageResource(R.drawable.user_image_male);
		}
		else if (ConstantPersonalInfo.sex.equals("2"))
		{
			sex.setText("性别: 女");
			userImage.setImageResource(R.drawable.user_image_female);
		}
		address.setText("地址: " + ConstantPersonalInfo.address);
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.title_bar_left_image_view:
				finish();
				break;
			case R.id.mine_layout_modify_accout:// 修改账户按钮
				Intent intent0 = new Intent(MineActivity.this, ModifyAccount.class);
				startActivity(intent0);
				break;
			case R.id.mine_layout_shopping_cart:// 购物车按钮
				Intent intent1 = new Intent(MineActivity.this, ShoppingCartActivity.class);
				startActivity(intent1);
				break;
			case R.id.mine_layout_comment:// 我的评论按钮
				Intent intent2 = new Intent(MineActivity.this, CommentListActivity.class);
				startActivity(intent2);
				break;
			
			default:
				break;
		}
	}
	
}
